package cn.janescott.inner.space.lib.support.pagination;

import org.springframework.util.CollectionUtils;

import java.util.List;

/**
 * 分页结果对象
 * Created by Scott on 2018/5/15
 */
public class PaginationResultDTO<T> implements java.io.Serializable {
    /**
     * 结果
     */
    private List<T> result;

    /**
     * 总数
     */
    private int total;

    /**
     * 每页大小
     */
    private int size;

    /**
     * 当前页码
     */
    private int page;

    public List<T> getResult() {
        return result;
    }

    public void setResult(List<T> result) {
        this.result = result;
    }

    public int getTotal() {
        return total;
    }

    public void setTotal(int total) {
        this.total = total;
    }

    public int getSize() {
        return size;
    }

    public void setSize(int size) {
        this.size = size;
    }

    public int getPage() {
        return page;
    }

    public void setPage(int page) {
        this.page = page;
    }

    public PaginationResultDTO() {
    }

    public PaginationResultDTO(PaginationDTO paginationDTO, List<T> result) {
        if (CollectionUtils.isEmpty(result)) {
            this.setTotal(0);
            this.setResult(null);
        } else {
            this.setResult(result);
            this.setTotal(paginationDTO.getTotal());
        }
    }
}
